package com.xiaoyi.intentsdklibrary.SDK.FloatView;

import android.content.Context;
import android.graphics.Path;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.Utils.StateBarUtil;

public class PathViewSDK {
    private static final PathViewSDK ourInstance = new PathViewSDK();
    private Handler mHandler;
    private WindowManager.LayoutParams mParams;
    private PathView mPathView;
    private Runnable mR;
    private WindowManager mWindowManager;

    public static PathViewSDK getInstance() {
        return ourInstance;
    }

    private PathViewSDK() {
    }

    public void init(Context context) {
        try {
            if (this.mWindowManager == null) {
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                this.mPathView = new PathView(context);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                this.mParams = layoutParams;
                layoutParams.flags = 152;
                this.mParams.format = -3;
                if (Build.VERSION.SDK_INT >= 26) {
                    this.mParams.type = 2038;
                } else {
                    this.mParams.type = 2003;
                }
                this.mParams.gravity = 8388659;
                this.mWindowManager.addView(this.mPathView, this.mParams);
                PathView pathView = this.mPathView;
                if (pathView != null) {
                    pathView.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void show(Context context, Path path, int i) {
        hide();
        try {
            if (ActionNormalSDK.getInstance().isScreenPortrait(context)) {
                path.offset(0.0f, (float) (StateBarUtil.getStatusBarHeight(context) * -1));
            } else {
                path.offset((float) (StateBarUtil.getStatusBarHeight(context) * -1), 0.0f);
            }
            this.mPathView.setPath(path);
            this.mWindowManager.updateViewLayout(this.mPathView, this.mParams);
            this.mPathView.setVisibility(View.VISIBLE);
            this.mPathView.postDelayed(new Runnable() {
                /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.PathViewSDK.AnonymousClass1 */

                public void run() {
                    PathViewSDK.this.mPathView.setVisibility(View.GONE);
                }
            }, (long) i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void hide() {
        try {
            this.mPathView.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
